package com.jd.controller;

import com.jd.entity.User;
import com.jd.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/user")
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/{id}")
    public User get(@PathVariable Integer id) {
        return userService.get(id);
    }


    @GetMapping("/xml/{id}")
    public User getByXml(@PathVariable Integer id) {
        return userService.getByXml(id);
    }

    @GetMapping("/list")
    public List<User> list() {
        return userService.list();
    }

    @GetMapping("/xml/list")
    public List<User> listByXml() {
        return userService.listByXml();
    }

    @GetMapping("/add")
    public User insert() {
        User user = new User();
        user.setId(1234);
        user.setName("王五");
        userService.save(user);
        return user;
    }

}
